package com.lwj.liwanjia.view.activity.personal;

import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.lwj.liwanjia.R;
import com.lwj.liwanjia.base.BaseActivity;
import com.lwj.liwanjia.base.MyApplication;
import com.lwj.liwanjia.utils.SpfUtils;
import com.lwj.liwanjia.view.activity.login.LoginActivity;

/**
 * 个人中心-设置-首页
 * Created by 001 on 2017/9/10.
 */

public class SheZhiActivity extends BaseActivity implements View.OnClickListener {

    private TextView tv_back;
    private TextView tv_title;
    private RelativeLayout rl_xiTong;
    private TextView btnNext;
    private TextView tvVersion;

    @Override
    protected void initView() {

        tv_back = (TextView) findViewById(R.id.tv_left);
        tv_title = (TextView) findViewById(R.id.tv_title);
        rl_xiTong = (RelativeLayout) findViewById(R.id.rl_xiTong);
        btnNext = (TextView) findViewById(R.id.bt_next);
        tvVersion = (TextView) findViewById(R.id.tv_version);

        tv_back.setVisibility(View.VISIBLE);
        tv_title.setVisibility(View.VISIBLE);
        tv_title.setText("设置");

        tv_back.setOnClickListener(this);
        rl_xiTong.setOnClickListener(this);
        btnNext.setOnClickListener(this);
        initVersion();
    }

    @Override
    protected void initData() {

    }
    /*获取版本号*/
    private void initVersion() {
        PackageManager packageManager = MyApplication.getInstance().getPackageManager();
        String packageName = MyApplication.getInstance().getPackageName();
        try {
            PackageInfo packageInfo = packageManager.getPackageInfo(packageName, 0);
            String versionName = packageInfo.versionName;
            tvVersion.setText("当前版本"+versionName);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_she_zhi;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            //返回
            case R.id.tv_left:
                finish();
                break;
            //系统设置
            case R.id.rl_xiTong:
                Toast.makeText(this, "暂未开通", Toast.LENGTH_SHORT).show();
//                startActivity(new Intent(SheZhiActivity.this, XiTongSheZhiActivity.class));
                break;
            case R.id.bt_next:
                startActivity(new Intent(this, LoginActivity.class).putExtra("type","退出登录"));
                MyApplication.getInstance().clearActivity();
                SpfUtils.getSpfUtils(this).setStoken("");
                finish();
                break;
        }
    }
}
